package com.example.a28796.beautiful.styAdapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.a28796.beautiful.R;
import com.example.a28796.beautiful.stybean.FuliBean;
import com.example.a28796.beautiful.stybean.SearchBean;

import java.util.List;

/**
 * Created by lenovo on 2016/8/31.
 */
public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.MyViewHolder> {
    private Context context;
    private List<SearchBean.ObjBean> mData;

    public SearchAdapter(Context context, List<SearchBean.ObjBean> mData) {
        this.context = context;
        this.mData = mData;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_button,null);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        SearchBean.ObjBean objBean = mData.get(position);
        int red = (int) (Math.random()*256);
        int green = (int) (Math.random()*256);
        int blue = (int) (Math.random()*256);
        int bgColor = Color.rgb(red,green,blue);
        holder.button.setTextColor(Color.WHITE);
        holder.button.setBackgroundColor(bgColor);
        holder.button.setText(objBean.getQ());
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder{
        private Button button;
        public MyViewHolder(View itemView) {
            super(itemView);
            button = (Button) itemView.findViewById(R.id.bt_item);
        }
    }
}
